package com.jcodecraeer.xrecyclerview.progressindicator.indicator;

import ohos.agp.animation.Animator;
import ohos.agp.animation.AnimatorValue;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;
import ohos.agp.utils.RectFloat;

import java.util.ArrayList;
import java.util.List;

public class SquareSpinIndicator extends BaseIndicatorController{
    private float scaleFloat=1;
    @Override
    public void draw(Canvas canvas, Paint paint) {
//        float x = (getWidth()*4/5 - getWidth()/5) / 2;
//        float y=(getHeight()*4/5 -getHeight()/5) / 2;
//
//        canvas.rotate(360*scaleFloat,x,y);
        canvas.drawRect(new RectFloat(getWidth()/5,getHeight()/5,getWidth()*4/5,getHeight()*4/5),paint);
    }

    @Override
    public List<Animator> createAnimation() {
        List<Animator> animators=new ArrayList<>();

        AnimatorValue scaleAnim = new AnimatorValue();
        scaleAnim.setDuration(2500);
        scaleAnim.setLoopedCount(-1);
        scaleAnim.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() {
            @Override
            public void onUpdate(AnimatorValue animatorValue, float v) {
                scaleFloat = v;
                getTarget().setRotation(v*180);
                postInvalidate();
            }
        });
        scaleAnim.start();
//        PropertyValuesHolder rotation5=PropertyValuesHolder.ofFloat("rotationX",0,180,180,0,0);
//        PropertyValuesHolder rotation6=PropertyValuesHolder.ofFloat("rotationY",0,0,180,180,0);
//
//        ObjectAnimator animator=ObjectAnimator.ofPropertyValuesHolder(getTarget(), rotation6,rotation5);
//        animator.setInterpolator(new LinearInterpolator());
//        animator.setRepeatCount(-1);
//        animator.setDuration(2500);
//        animator.start();
//        animators.add(mAnimatorSet);

        return animators;
    }
}
